#!/usr/bin/perl -w
use strict;
use DBI;
use JSON;use Data::Dumper;my $input = <>; chomp $input; my $json = new JSON;my $perlOb = $json->jsonToObj($input);
my $db = "tar";
my $status_table = "status";
my $city ="blr"; #hardcoded for now since we have only one city
my $acode="area_code";
my $dbh = DBI->connect('DBI:mysql:tar','fbads','fbads') or die "Couldn't connect to database: " . DBI->errstr;
my $sth = $dbh->prepare("delete from $status_table where $acode = ?")  or die "Couldn't prepare statement: " . $dbh->errstr;
my $sth1 = $dbh->prepare("insert into $status_table values(?,?,?,?)")  or die "Couldn't prepare statement: " . $dbh->errstr;
my @location = $perlOb->{'locations'};
foreach  my $key (  @location ) {
	my @values = @$key;
	foreach my $value(@values) {
		my @values1 = @$value;
		my $str = "";
	#foreach my $value1(@values1) {
		if (!$values1[4] ) {
		$values1[4] = $values1[0];
		$values1[4] =~ s/,//g;
		$values1[4] =~ s/\ //g;
		}
		$sth->execute($values1[4]);
		$sth1->execute($city,$values1[4],$values1[0],$values1[3]);
			#}

	}
}
$dbh->disconnect();
